package com.ljw.gulimall.order.listener;

import com.ljw.gulimall.order.service.OrderService;
import com.ljw.gulimall.order.vo.PayAsyncVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
public class OrderPayedListener {


    @Autowired
    private OrderService orderService;

    @PostMapping("/payed/notify")
    public String handleAlipayed(PayAsyncVo payAsyncVo, HttpServletRequest request){
        //只要我们收到了支付宝给我们异步的通知，告诉我们订单支付成功。返回success，支付宝就再也不通知我们
//        Map<String, String[]> parameterMap = request.getParameterMap();
//        for (String key : parameterMap.keySet()) {
//            String value = request.getParameter(key);
//            System.out.println(value);
//        }
        String result = orderService.handlePayResult(payAsyncVo);
        //TODO 验签 判断是否是支付宝发给我们的数据
        System.out.println("异步调用成功：" + result);
        System.out.println(payAsyncVo);

        return result;
    }

}
